package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TMessageRead;
import com.ruoyi.business.service.ITMessageReadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息已读记录Controller
 * 
 * @author laoguo
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/business/read")
public class TMessageReadController extends BaseController
{
    @Autowired
    private ITMessageReadService tMessageReadService;

    /**
     * 查询消息已读记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:read:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMessageRead tMessageRead)
    {
        startPage();
        List<TMessageRead> list = tMessageReadService.selectTMessageReadList(tMessageRead);
        return getDataTable(list);
    }

    /**
     * 导出消息已读记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:read:export')")
    @Log(title = "消息已读记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMessageRead tMessageRead)
    {
        List<TMessageRead> list = tMessageReadService.selectTMessageReadList(tMessageRead);
        ExcelUtil<TMessageRead> util = new ExcelUtil<TMessageRead>(TMessageRead.class);
        util.exportExcel(response, list, "消息已读记录数据");
    }

    /**
     * 获取消息已读记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:read:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(tMessageReadService.selectTMessageReadByRecordId(recordId));
    }

    /**
     * 新增消息已读记录
     */
    @PreAuthorize("@ss.hasPermi('business:read:add')")
    @Log(title = "消息已读记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMessageRead tMessageRead)
    {
        return toAjax(tMessageReadService.insertTMessageRead(tMessageRead));
    }

    /**
     * 修改消息已读记录
     */
    @PreAuthorize("@ss.hasPermi('business:read:edit')")
    @Log(title = "消息已读记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMessageRead tMessageRead)
    {
        return toAjax(tMessageReadService.updateTMessageRead(tMessageRead));
    }

    /**
     * 删除消息已读记录
     */
    @PreAuthorize("@ss.hasPermi('business:read:remove')")
    @Log(title = "消息已读记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(tMessageReadService.deleteTMessageReadByRecordIds(recordIds));
    }
}
